<%--
  Created by IntelliJ IDEA.
  User: yajuan.wang
  Date: 2018/12/12
  Time: 9:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>Title</title>
    <style>
        a {
            text-decoration: none;
            color: #0C0C0C;
            font-size: 12px;
        }

        .jOrgChart .node {
            width: 120px;
            height: 50px;
            line-height: 50px;
            border-radius: 4px;
            margin: 0 8px;
            background-color: #84cdf7;
        }
        .jOrgChart{
            margin: 20px auto;
            width: auto;
        }
    </style>
</head>
<body>
<div id='jOrgChart'></div>

</body>
<script type='text/javascript'>
    $(function () {
        tree();


    });

    function tree() {
        $("#jOrgChart").empty();
        //数据返回
        $.ajax({
            url: "<c:url value="/web/admin/organization/getOrganizationMsg.action"/>",
            type: 'GET',
            dataType: 'JSON',
            success: function (result) {
                var data = result.data;
                var showlist = $("<ul id='org' style='display:none'></ul>");
                showall(data, showlist);
                $("#jOrgChart").append(showlist);
                $("#org").jOrgChart({
                    chartElement: '#jOrgChart',//指定在某个dom生成jorgchart
                    dragAndDrop: true //设置是否可拖动
                });
            }
        });

    }


    function showall(menu_list, parent) {
        $.each(menu_list, function (index, val) {
            if (val.childrens.length > 0) {

                var li = $("<li style='text-align: center'></li>");
                li.append("<a href='javascript:void(0)' id='" + val.id + "'>" + val.name + "</a>").append("<ul></ul>").appendTo(parent);
                //递归显示
                showall(val.childrens, $(li).children().eq(1));
            } else {
                $("<li></li>").append("<a href='javascript:void(0)'  id='" + val.id + "'>" + val.name + "</a>").appendTo(parent);
            }
        });

    }

    function closeView() {
        layer.close(LayWin['vOrganization']);
    }

</script>

</html>
